package src;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.io.File;

import javax.swing.AbstractButton;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
import javax.swing.border.BevelBorder;

import resources.CaractPosition;
import resources.Document;
import resources.Ferramentas;
import resources.WindowActions;

public class Window extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JTextArea txtCodigo;
	private JLabel lblCaractPosition;
	private JButton btnAbrir;
	private JButton btnSalvar;
	private JButton btnRecortar;
	private JButton btnCopiar;
	private AbstractButton btnColar;
	private JButton btnX;
	private AbstractButton btnDesfazer;
	private JSplitPane splitPane;
	private JPanel panel;
	private JComponent lblNewLabel_1;
	private JLabel lblNewLabel_2;
	private JMenuBar menuBar;
	private JMenuItem mntmNovo;
	private JMenu mnArquivo;
	private JMenuItem mntmAbrir;
	private JMenuItem mntmSalvar;
	private JMenuItem mntmSalvarComo;
	private JMenuItem mntmSair;
	private JMenu mnEdio;
	private JMenuItem mntmColar;
	private JMenuItem mntmCopiar;
	private JMenuItem mntmRecortar;
	private JMenuItem mntmExecutar;
	private JMenuItem mntmCompilar;
	private JMenu mnCompilao;
	private JToolBar toolBar;
	private JButton btnNovo;

	private JFileChooser openFilePanel;

	private File file;
	private JTextArea txtrConsole;
	private Ferramentas ferramentas;
	private WindowActions actions;
	private CaractPosition caretPosition;
		
	/**
	 * Create the application.
	 */
	public Window() {
		setCaractPosition(new CaractPosition(this));
		setFerramentas(new Ferramentas(this));
		actions = new WindowActions(this);
		Document.setContent(this);
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
	
		openFilePanel = new JFileChooser();

		this.setBounds(100, 100, 640, 480);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.getContentPane().setLayout(new BorderLayout(0, 0));
		this.setTitle("Compilador");

		toolBar = new JToolBar();
		this.getContentPane().add(toolBar, BorderLayout.NORTH);

		btnNovo = new JButton("");
		btnNovo.setIcon(new ImageIcon(Window.class.getResource(Icon.NOVO
				.getUrlFile())));
		btnNovo.setFocusPainted(false);
		btnNovo.setToolTipText("Novo");
		btnNovo.addActionListener(actions);
		toolBar.add(btnNovo);

		btnAbrir = new JButton("");
		btnAbrir.setIcon(new ImageIcon(Window.class.getResource(Icon.OPEN
				.getUrlFile())));
		btnAbrir.setToolTipText("Abrir");
		btnAbrir.addActionListener(actions);
		toolBar.add(btnAbrir);

		btnSalvar = new JButton("");
		btnSalvar.setIcon(new ImageIcon(Window.class.getResource(Icon.SAVE
				.getUrlFile())));
		btnSalvar.setToolTipText("Salvar");
		btnSalvar.addActionListener(actions);
		toolBar.add(btnSalvar);

		btnRecortar = new JButton("");
		btnRecortar.setIcon(new ImageIcon(Window.class.getResource(Icon.CUT
				.getUrlFile())));
		btnRecortar.setToolTipText("Recortar");
		btnRecortar.addActionListener(actions);
		toolBar.add(btnRecortar);

		btnCopiar = new JButton("");
		btnCopiar.setIcon(new ImageIcon(Window.class.getResource(Icon.COPY
				.getUrlFile())));
		btnCopiar.setToolTipText("Copiar");
		btnCopiar.addActionListener(actions);
		toolBar.add(btnCopiar);

		btnColar = new JButton("");
		btnColar.setIcon(new ImageIcon(Window.class.getResource(Icon.PASTE
				.getUrlFile())));
		btnColar.setToolTipText("Colar");
		btnColar.addActionListener(actions);
		toolBar.add(btnColar);

		btnX = new JButton("");
		btnX.setIcon(new ImageIcon(Window.class.getResource(Icon.REMOVE
				.getUrlFile())));
		btnX.setToolTipText("Remover");
		btnX.addActionListener(actions);
		toolBar.add(btnX);

		btnDesfazer = new JButton("");
		btnDesfazer.setIcon(new ImageIcon(Window.class.getResource(Icon.UNDO
				.getUrlFile())));
		btnDesfazer.setToolTipText("Desfazer");
		btnDesfazer.addActionListener(actions);
		toolBar.add(btnDesfazer);

		splitPane = new JSplitPane();
		splitPane.setResizeWeight(0.75);
		splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
		this.getContentPane().add(splitPane, BorderLayout.CENTER);

		txtCodigo = new JTextArea();
		txtCodigo.setText("edicao");
		txtCodigo.setTabSize(8);
		txtCodigo.getDocument().addDocumentListener(actions);
		
		splitPane.setLeftComponent(txtCodigo);

		txtrConsole = new JTextArea();
		txtrConsole.setText("Console");
		txtrConsole.setEditable(false);
		splitPane.setRightComponent(txtrConsole);

		panel = new JPanel();
		this.getContentPane().add(panel, BorderLayout.SOUTH);
		panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));

		lblCaractPosition = new JLabel(" Linha - Coluna -  ");
		lblCaractPosition.setBorder(new BevelBorder(BevelBorder.LOWERED, null,
				null, null, null));
		panel.add(lblCaractPosition);

		lblNewLabel_1 = new JLabel("  asdaasdasdasda  ");
		lblNewLabel_1.setBorder(new BevelBorder(BevelBorder.LOWERED, null,
				null, null, null));
		panel.add(lblNewLabel_1);

		lblNewLabel_2 = new JLabel("qualquer outra coisa");
		lblNewLabel_2.setBorder(new BevelBorder(BevelBorder.LOWERED, null,
				null, null, null));
		lblNewLabel_2
				.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
		lblNewLabel_2.setMaximumSize(new Dimension(3000, 3000));
		lblNewLabel_2.setAlignmentX(Component.CENTER_ALIGNMENT);
		panel.add(lblNewLabel_2);

		menuBar = new JMenuBar();
		this.setJMenuBar(menuBar);

		mnArquivo = new JMenu("Arquivo");
		menuBar.add(mnArquivo);

		mntmNovo = new JMenuItem("Novo");
		mntmNovo.addActionListener(actions);
		mnArquivo.add(mntmNovo);

		mntmAbrir = new JMenuItem("Abrir");
		mntmAbrir.addActionListener(actions);
		mnArquivo.add(mntmAbrir);

		mntmSalvar = new JMenuItem("Salvar");
		mntmSalvar.addActionListener(actions);
		mnArquivo.add(mntmSalvar);

		mntmSalvarComo = new JMenuItem("Salvar como");
		mntmSalvarComo.addActionListener(actions);
		mnArquivo.add(mntmSalvarComo);

		mntmSair = new JMenuItem("Sair");
		mntmSair.addActionListener(actions);
		mnArquivo.add(mntmSair);

		mnEdio = new JMenu("Edi\u00E7\u00E3o");
		mnEdio.addActionListener(actions);
		menuBar.add(mnEdio);

		mntmCopiar = new JMenuItem("Copiar");
		mntmCopiar.addActionListener(actions);
		mnEdio.add(mntmCopiar);

		mntmColar = new JMenuItem("Colar");
		mntmColar.addActionListener(actions);
		mnEdio.add(mntmColar);

		mntmRecortar = new JMenuItem("Recortar");
		mntmRecortar.addActionListener(actions);
		mnEdio.add(mntmRecortar);

		mnCompilao = new JMenu("Compila\u00E7\u00E3o");
		mnCompilao.addActionListener(actions);
		menuBar.add(mnCompilao);

		mntmCompilar = new JMenuItem("Compilar");
		mntmCompilar.addActionListener(actions);
		mnCompilao.add(mntmCompilar);

		mntmExecutar = new JMenuItem("Executar");
		mntmExecutar.setEnabled(false);
		mntmExecutar.addActionListener(actions);
		mnCompilao.add(mntmExecutar);

		txtCodigo.addCaretListener(caretPosition);

	}

	public JTextArea getTxtCodigo() {
		return txtCodigo;
	}

	public void setTxtCodigo(JTextArea txtCodigo) {
		this.txtCodigo = txtCodigo;
	}

	public JLabel getLblCaractPosition() {
		return lblCaractPosition;
	}

	public void setLblCaractPosition(JLabel lblCaractPosition) {
		this.lblCaractPosition = lblCaractPosition;
	}

	public JButton getBtnAbrir() {
		return btnAbrir;
	}

	public void setBtnAbrir(JButton btnAbrir) {
		this.btnAbrir = btnAbrir;
	}

	public JButton getBtnSalvar() {
		return btnSalvar;
	}

	public void setBtnSalvar(JButton btnSalvar) {
		this.btnSalvar = btnSalvar;
	}

	public JButton getBtnRecortar() {
		return btnRecortar;
	}

	public void setBtnRecortar(JButton btnRecortar) {
		this.btnRecortar = btnRecortar;
	}

	public JButton getBtnCopiar() {
		return btnCopiar;
	}

	public void setBtnCopiar(JButton btnCopiar) {
		this.btnCopiar = btnCopiar;
	}

	public AbstractButton getBtnColar() {
		return btnColar;
	}

	public void setBtnColar(AbstractButton btnColar) {
		this.btnColar = btnColar;
	}

	public JButton getBtnX() {
		return btnX;
	}

	public void setBtnX(JButton btnX) {
		this.btnX = btnX;
	}

	public AbstractButton getBtnDesfazer() {
		return btnDesfazer;
	}

	public void setBtnDesfazer(AbstractButton btnDesfazer) {
		this.btnDesfazer = btnDesfazer;
	}

	public JSplitPane getSplitPane() {
		return splitPane;
	}

	public void setSplitPane(JSplitPane splitPane) {
		this.splitPane = splitPane;
	}

	public JPanel getPanel() {
		return panel;
	}

	public void setPanel(JPanel panel) {
		this.panel = panel;
	}

	public JComponent getLblNewLabel_1() {
		return lblNewLabel_1;
	}

	public void setLblNewLabel_1(JComponent lblNewLabel_1) {
		this.lblNewLabel_1 = lblNewLabel_1;
	}

	public JLabel getLblNewLabel_2() {
		return lblNewLabel_2;
	}

	public void setLblNewLabel_2(JLabel lblNewLabel_2) {
		this.lblNewLabel_2 = lblNewLabel_2;
	}

	public void setMenuBar(JMenuBar menuBar) {
		this.menuBar = menuBar;
	}

	public JMenuItem getMntmNovo() {
		return mntmNovo;
	}

	public void setMntmNovo(JMenuItem mntmNovo) {
		this.mntmNovo = mntmNovo;
	}

	public JMenu getMnArquivo() {
		return mnArquivo;
	}

	public void setMnArquivo(JMenu mnArquivo) {
		this.mnArquivo = mnArquivo;
	}

	public JMenuItem getMntmAbrir() {
		return mntmAbrir;
	}

	public void setMntmAbrir(JMenuItem mntmAbrir) {
		this.mntmAbrir = mntmAbrir;
	}

	public JMenuItem getMntmSalvar() {
		return mntmSalvar;
	}

	public void setMntmSalvar(JMenuItem mntmSalvar) {
		this.mntmSalvar = mntmSalvar;
	}

	public JMenuItem getMntmSalvarComo() {
		return mntmSalvarComo;
	}

	public void setMntmSalvarComo(JMenuItem mntmSalvarComo) {
		this.mntmSalvarComo = mntmSalvarComo;
	}

	public JMenuItem getMntmSair() {
		return mntmSair;
	}

	public void setMntmSair(JMenuItem mntmSair) {
		this.mntmSair = mntmSair;
	}

	public JMenu getMnEdio() {
		return mnEdio;
	}

	public void setMnEdio(JMenu mnEdio) {
		this.mnEdio = mnEdio;
	}

	public JMenuItem getMntmColar() {
		return mntmColar;
	}

	public void setMntmColar(JMenuItem mntmColar) {
		this.mntmColar = mntmColar;
	}

	public JMenuItem getMntmCopiar() {
		return mntmCopiar;
	}

	public void setMntmCopiar(JMenuItem mntmCopiar) {
		this.mntmCopiar = mntmCopiar;
	}

	public JMenuItem getMntmRecortar() {
		return mntmRecortar;
	}

	public void setMntmRecortar(JMenuItem mntmRecortar) {
		this.mntmRecortar = mntmRecortar;
	}

	public JMenuItem getMntmExecutar() {
		return mntmExecutar;
	}

	public void setMntmExecutar(JMenuItem mntmExecutar) {
		this.mntmExecutar = mntmExecutar;
	}

	public JMenuItem getMntmCompilar() {
		return mntmCompilar;
	}

	public void setMntmCompilar(JMenuItem mntmCompilar) {
		this.mntmCompilar = mntmCompilar;
	}

	public JMenu getMnCompilao() {
		return mnCompilao;
	}

	public void setMnCompilao(JMenu mnCompilao) {
		this.mnCompilao = mnCompilao;
	}

	public JToolBar getToolBar() {
		return toolBar;
	}

	public void setToolBar(JToolBar toolBar) {
		this.toolBar = toolBar;
	}

	public JButton getBtnNovo() {
		return btnNovo;
	}

	public void setBtnNovo(JButton btnNovo) {
		this.btnNovo = btnNovo;
	}

	public JFileChooser getOpenFilePanel() {
		return openFilePanel;
	}

	public void setOpenFilePanel(JFileChooser openFilePanel) {
		this.openFilePanel = openFilePanel;
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public JTextArea getTxtrConsole() {
		return txtrConsole;
	}

	public void setTxtrConsole(JTextArea txtrConsole) {
		this.txtrConsole = txtrConsole;
	}

	public CaractPosition getCaractPosition() {
		return caretPosition;
	}

	public void setCaractPosition(CaractPosition caretPosition) {
		this.caretPosition = caretPosition;
	}

	public Ferramentas getFerramentas() {
		return ferramentas;
	}

	public void setFerramentas(Ferramentas ferramentas) {
		this.ferramentas = ferramentas;
	}
}
